package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.CacheUtils;
import com.ruoyi.system.domain.UserBaseGroup;
import com.ruoyi.system.mapper.UserBaseGroupMapper;
import com.ruoyi.system.service.UserBaseGroupService;
import com.ruoyi.system.utils.DictUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;

/**
 * @Author tang ao long
 * @Date 2020-08-30 21:28
 * @Version 1.0
 */
@Service
public class UserBaseGroupServiceImpl implements UserBaseGroupService {

    @Autowired
    private UserBaseGroupMapper userBaseGroupMapper;

    /**
     * 查询大屏分组信息
     *
     * @param userBaseGroup 大屏分组
     * @return 返回
     */
    @Override
    public List<UserBaseGroup> selectUserBaseGroupByInfo(UserBaseGroup userBaseGroup) {
        return userBaseGroupMapper.selectUserBaseGroupByInfo(userBaseGroup);
    }

    /**
     * 根据id批量删除
     *
     * @param ids 批量删除的id
     * @return 返回删除结果
     */
    @Override
    public Integer deleteUserBaseGroupByIds(String ids) {
        int count = userBaseGroupMapper.deleteUserBaseGroupByIds(Convert.toStrArray(ids));
        if(count > 0){
            CacheUtils.removeAll(DictUtils.getCacheName());
        }
        return count;
    }

    /**
     * 更新分组信息
     *
     * @param userBaseGroup 分组信息修改
     * @return 返回修改成果
     */
    @Override
    public Integer updateUserBaseGroupById(UserBaseGroup userBaseGroup) {
        return userBaseGroupMapper.updateUserBaseGroupById(userBaseGroup);
    }

    /**
     * 检查分组名称唯一性
     *
     * @param groupName 分组名称
     * @param id        分组ID
     * @return 返回检查结果
     */
    @Override
    public Integer checkUserBaseGroupUnique(String groupName, String id) {
        return userBaseGroupMapper.checkUserBaseGroupUnique(groupName, id);
    }

    /**
     * 根据ID信息查询用户分组信息对象
     *
     * @param id 分组ID
     * @return 返回用户分组信息
     */
    @Override
    public UserBaseGroup selectUserBaseGroupInfoById(String id) {
        return userBaseGroupMapper.selectUserBaseGroupInfoById(id);
    }
}
